// Playground - noun: a place where people can play

import UIKit

var str = "Hello, " + "playground"

for character in str {
    println(character)
}

// tuples
let http404Error = (404, "Not Found")

1..<3
1...3

// function
func aFunction(externalParameterName localParameterName: Int) {
    println("\(localParameterName)")
}
aFunction(externalParameterName: 5)

func bFunction(#parameterName: Int) {
    println("\(parameterName)")
}
bFunction(parameterName: 3)

func join(s1: String, s2: String, joiner: String = " ") -> String {
    return s1 + joiner + s2
}
join("a", "b")

/*
func alignRight(var string: String, count: Int, pad: Character) -> String {
    let amountToPad = count - countElements(string)
    for _ in 1...amountToPad {
        string = pad + string
    }
    return string
}
let originalString = "hello"
let paddedString = alignRight(originalString, 10, "-")
*/

func swapTwoInts(inout a: Int, inout b: Int) {
    let temp = a
    a = b
    b = temp
}
var a = 1
var b = 2
swapTwoInts(&a, &b)
a
b

//func stepForward(input: Int) -> Int {
//    return input + 1
//}
//func stepBackward(input: Int) -> Int {
//    return input - 1
//}
//func chooseStep(backwards: Bool) -> (Int) -> Int {
//    return backwards ? stepBackward : stepForward
//}
//var current = 3
//let moveNearerToZero = chooseStep(current > 0)


func chooseStep(backwards: Bool) -> (Int) -> Int {
    func stepForward(input: Int) -> Int { return input + 1 }
    func stepBackward(input: Int) -> Int { return input - 1 }
    return backwards ? stepBackward : stepForward
}
var value = -4
let moveNearerTo0 = chooseStep(value > 0)